<!-- $Id $ -->
{include file="pageheader.htm"}
{insert_scripts files="../js/utils.js,listtable.js,validator.js,selectzone2.js"}
<script type="text/javascript" src="../js/calendar.php?lang={$cfg_lang}"></script>
<link href="../js/calendar/calendar.css" rel="stylesheet" type="text/css" />
<div class="main-div">
<form method="post" action="goods_aa.php" name="theForm" onsubmit="return validate()">
<table cellspacing="1" cellpadding="3" width="100%">
  <tr>
    <td class="label">{$lang.package_name}</td>
    <td><input type="text" name="act_name" maxlength="60" size="40" value="{$package.act_name}" />{$lang.require_field}</td>
  </tr>

  <tr>
    <td class="label">活动类型：</td>
	<td><select name="act_type">{$activity_list_options}</select></td>
  </tr>

  <tr>
    <td class="label">所属行业：</td>
	<td><select name="cat2_id">{$cat_list2_options}</select></td>
  </tr>

  <tr>
    <td class="label">套装稿件描述：</td>
    <td><textarea  name="desc" cols="60" rows="4">{$package.act_desc}</textarea></td>
  </tr>
  <!-- 商品搜索 -->
  <tr>
    <td class="label">
      {$lang.search_goods}
    </td>
    <td>
      <select name="cat_id"><option value="0">{$lang.all_category}</caption>{$cat_list}</select>
      <input type="text" name="keyword" />
      <input type="button" value="{$lang.button_search}" onclick="javascript:searchGoods();" class="button" />
    </td>
  </tr>
  <tr>
    <td colspan="2">
      <table id="groupgoods-table" align="center" style="width:80%;">
        <!-- 商品列表 -->
        <tr>
          <th>{$lang.all_goods}</th>
          <th>{$lang.handler}</th>
          <th>{$lang.package_goods}</th>
        </tr>
        <tr>
          <td width="30%">
            <select name="source_select" size="15" style="width:100%" onchange="this.form.elements['number'].value = 1" ondblclick="sz.addItem(false, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)">
            </select>
          </td>
          <td width="10%" align="center">
            <p><input name="number" type="hidden" size="6" value="1" /></p>
			<!--
            <p><input type="button" value="{$lang.aabb_add_all}" onclick="sz.addItem(true, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)" class="button" /></p>
			<p><input type="button" value="{$lang.aabb_drop_all}" onclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)" class="button" /></p>-->
            <p><input type="button" value="{$lang.aabb_add}" onclick="sz.addItem(false, 'add_package_goods', this.form.elements['id'].value, this.form.elements['number'].value)" class="button" /></p>
            <p><input type="button" value="{$lang.aabb_drop}" onclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)" class="button" /></p>
          </td>
          <td width="60%" style="border:1px solid #ddd;line-height:22px;">
		  
			<table width="100%" id="goods_aa_list" style="">
				 {foreach from=$package_goods_list item=package_goods}
				<tr>
					<td width="50"><input type="checkbox" name="box_select" value="{$package_goods.goods_id}"/></td>
					<td width="120" height="120"><img src="../{$package_goods.goods_img}" style="width:120px;height:120px;border:1px solid #ddd;"></td>
					<td>
					{$lang.goods_name2}{$package_goods.goods_name}<br/>
					{$lang.cat_name}{$package_goods.cat_name}<br/>
					{$lang.cat2_name}{$package_goods.cat2_name}<br/>
					设计风格：{$package_goods.act_id_name}<br/>
					规格尺寸：{$package_goods.goods_size}<br/>						
					</td>
				</tr>
				 {/foreach}
			
			</table>
			
            <select name="target_select" size="15" style="width:100%;display:none;" multiple ondblclick="sz.dropItem(false, 'drop_package_goods', this.form.elements['id'].value)">
              {foreach from=$package_goods_list item=package_goods}
              <option value="{$package_goods.goods_id}">{$package_goods.goods_name}</option>
              {/foreach}
            </select>
          </td>
        </tr>
      </table>
    </td>
  </tr>

  <tr>
    <td colspan="2" align="center">
      <input type="submit" value="{$lang.button_submit}" class="button" />
      <input type="reset" value="{$lang.button_reset}" class="button" />
      <input type="hidden" name="act" value="{$form_action}" />
      <input type="hidden" name="id" value="{$package.act_id}" />
    </td>
  </tr>
</table>
</form>
</div>
<script language="JavaScript">
<!--
{literal}
document.forms['theForm'].elements['act_name'].focus();
var elements = document.forms['theForm'].elements;
var sz = new SelectZone(2, elements['source_select'], elements['target_select'], elements['number']);
onload = function()
{
    // 开始检查订单
   // startCheckOrder();
}

/**
 * 检查表单输入的数据
 */
function validate()
{
    validator = new Validator("theForm");
    validator.required("act_name",  no_name);
    return validator.passed();
}

function searchGoods()
{
    var filter = new Object;
    filter.keyword    = document.forms['theForm'].elements['keyword'].value;
    filter.cat_id     = document.forms['theForm'].elements['cat_id'].value;
    //filter.brand_id   = document.forms['theForm'].elements['brand_id'].value;

    Ajax.call('goods_aa.php?is_ajax=1&act=search_goods', filter, searchGoodsResponse, 'GET', 'JSON')
}

function searchGoodsResponse(result)
{
  var frm = document.forms['theForm'];
  var sel = frm.elements['source_select'];

  if (result.error == 0)
  {
    /* 清除 options */
    sel.length = 0;

    /* 创建 options */
    var goods = result.content;
    if (goods)
    {
        for (i = 0; i < goods.length; i++)
        {
            /* 货品 options */
            if (goods[i].products.length > 0)
            {
              for (var j = 0; goods[i].products[j]; j++)
              {
                var opt = document.createElement("OPTION");
                opt.value = goods[i].value + '_' + goods[i].products[j].product_id;
                opt.text  = goods[i].text + '[' + goods[i].products[j].goods_attr_str + ']';
                sel.options.add(opt);
              }
            }
            else
            {
              var opt = document.createElement("OPTION");
              opt.value = goods[i].value;
              opt.text  = goods[i].text;
              sel.options.add(opt);
            }
        }
    }
    else
    {
        var opt = document.createElement("OPTION");
        opt.value = 0;
        opt.text  = search_is_null;
        sel.options.add(opt);
    }
  }

  if (result.message.length > 0)
  {
    alert(result.message);
  }
}

/* 关联商品函数 */
//function searchGoods_list(szObject, catId, brandId, keyword)
//{
//  var filters = new Object;
//
//  filters.cat_id = elements[catId].value;
//  filters.brand_id = elements[brandId].value;
//  filters.keyword = Utils.trim(elements[keyword].value);
//
//  szObject.loadOptions('get_goods_list', filters);
//}
//-->
{/literal}
</script>
{include file="pagefooter.htm"}